<?php

/**
 * Contrôleur des notations
 */
class notation_controller extends Component
{
    /**
     * Constructeur
     */
    public function __construct()
    {
    }

    public function defaut()
    {
        $objectID = $_POST['idBox'];
        $rate = $_POST['rate'];;
        $object = Base::Load(CLASS_CONTENT_MANAGER)->findOne($objectID);
        if (isset($object['n_total'])) {
            $object['n_total'] += $rate;
            $object['n_nb']++;
        } else {
            $object['n_total'] = $rate;
            $object['n_nb']= 1;
        }

        Base::Load(CLASS_CONTENT_MANAGER)->save($object, $objectID);
    }

    public function notationMagasin()
    {
        $objectID = $_POST['idBox'];
        $rate = $_POST['rate'];;
        $object = Base::Load(CLASS_CONTENT_MANAGER)->findOne($objectID);
        if (isset($object['n_total'.$_GET['param'][0]])) {
            $object['n_total'.$_GET['param'][0]] += $rate;
            $object['n_nb'.$_GET['param'][0]]++;
        } else {
            $object['n_total'.$_GET['param'][0]] = $rate;
            $object['n_nb'.$_GET['param'][0]]= 1;
        }

        Base::Load(CLASS_CONTENT_MANAGER)->save($object, $objectID);
    }

}


/* -- Fin du fichier -- */